<?php

//搜索页面

namespace M\Controller;
use Think\Controller;

class MemberController extends CommonController {
    public function index() {
        $mid = $this->memberinfo['id'];
        // $mid = 1;
        $data = $this->_get_member_additional_info($mid);

        // print_r($data); die;
        $this->assign('data',$data);
        $this->assign("memberinfo", $this->memberinfo);        
        $this->display();
    }
    
    /*
     * Date: 2015-10-19
     * Des: 通知中心
     */
    public function notifition_center() {
        
    }
    
    
    /*
        * 判断是否支付了该订单
        */
       private function _chk_founding_payment_status($fdid) {
           $map['fid']=$fdid;
           $map['status']=1;
           $DB = M("fundings_sponsor");
           
           $res = $DB->where($map)->find();
           
           if(!empty($res))
           {
               return TRUE;
           }
           else
           {
               return FALSE;
           }
           
           
       }
    
    
    
    /*
     * 获取套餐资料
     */
    private function get_name_by_packageid($id) {
        /*
         * 判断id 是单个还是多少
         */
        $id_arr = explode(',', $id);
        $DB = M('fundings_package');
        $name="";
        foreach ($id_arr as $key => $value) {
            $res[$key] = $DB->find($value);
            $name .=",".$res[$key]['name'];
//            echo $name;
        }
        
        
        
        return substr($name, 1);
    }
    
     /*
     * 计算项目要显示的图标
     */
     protected function _get_fouding_list_mark($type=0,$isqualified,$state) {
        switch ($state) {
            case 0:

//                return "img/verifying_mark.png";
                return "img/fouding_mark.png";
                break;
            case 1:
                return "img/fouding_mark.png";
                break;
            case 2:
                return "img/testing_mark.png";

                break;
            case 3:
                if($isqualified==1)
                {
                    return "img/qualified_mark.png";
                }
                else
                {
                    return "img/unqualified_mark.png";
                }
                break;
            case 4:
                return "img/cancel_mark.png";

                break;

            default:
                return "img/testing_mark.png";
                break;
        }
        
    }

    //我发起的项目
    private function get_my_setup($mid){

        $map['mid'] = $mid;
        $User = M('fundings');

        $my_setup = $User->where($map)->select();

        if(!empty($my_setup)){

            return $my_setup;
        }
    }


    public function feedback(){
        if(IS_GET){

            $this->display();
        }
    }

    public function put_feedback(){

        if(IS_AJAX){
            $mid = $this->memberinfo['id'];
            $contact = I('post.contact');
            $content = I('post.content');

            if(!empty($contact)){

                $data['contact'] = $contact;
            }
            if(!empty($content)){

                $data['content'] = $content;
            }

            $data['ctime'] = I('server.REQUEST_TIME');
            $data['mid'] = $mid;
            $User = M('feedback');
            $result = $User->data($data)->add();

            if(!empty($result)){

                echo json_encode(1);
            }else{

                echo json_encode(0);
            }
        }
    }


    //个人资料修改
    //
    public function my_profile(){

        if(IS_GET){
            $map['id'] = $this->memberinfo['id'];

            $User = M('members');

            $list = $User->where($map)->find();
            
            $this->assign('list',$list);            
            $this->display();
        }
    }


    //修改手机号码
    public function modify_mobile(){

        if(IS_GET){
            $this->assign("memberinfo", $this->memberinfo);
            $this->display();
        }else if(IS_AJAX){

            $mobile = I('post.mobile');
            // echo  json_encode(2); die;
            if(!empty($mobile)){

                $data['mobile'] = $mobile;
            }
            $map['id'] = $this->memberinfo['id'];

            $User = M('members');

            $result = $User->where($map)->data($data)->save();
            if(!empty($result)){

                echo json_encode(1);
            }else{

                echo json_encode(0);
            }
        }
    }

    //修改性别
    public function modify_sex(){

        if(IS_GET){

            $this->display();
        }else if(IS_AJAX){

            $sex = I('post.sex');
            // echo  json_encode(2); die;
            if(isset($sex)){

                $data['gender'] = $sex;
            }
            $map['id'] = $this->memberinfo['id'];

            $User = M('members');

            $result = $User->where($map)->data($data)->save();
            if(!empty($result)){

                echo json_encode(1);
            }else{

                echo json_encode(0);
            }
        }
    }



    //修改生日信息
    public function modify_birthday(){

         if(IS_GET){
            $member = $this->memberinfo;
            $member['birthday_s'] = $this->sub_str_birthday($member['birthday']);
            $this->assign("memberinfo", $member);
            $this->display();
        }else if(IS_AJAX){

            $birthday = I('post.birthday');
            // echo $birthday;die;
            if(!empty($birthday)){

                $data['birthday'] = $birthday;
            }

            $map['id'] = $this->memberinfo['id'];

            $User = M('members');

            $result = $User->where($map)->data($data)->save();
            if(!empty($result)){

                echo json_encode(1);
            }else{

                echo json_encode(0);
            }
        }
    }

    //自动截取生日
    private function sub_str_birthday($bir){

        $birthday['year'] = substr($bir,0,4);
        $birthday['month'] = substr($bir,5,2);
        $birthday['day'] = substr($bir,8,2);

        if(substr($birthday['month'],0,1)=='0'){
            $birthday['month'] = substr($birthday['month'],1,1);
        }else{
            $birthday['month'] = $birthday['month'];
        }

        if(substr($birthday['day'],0,1)=='0'){
            $birthday['day'] = substr($birthday['day'],1,1);
        }else{
            $birthday['day'] = $birthday['day'];
        }
        return $birthday;
    }


    //修改用户的详细地址
    public function modify_location(){

        if(IS_GET){
            $this->assign("memberinfo", $this->memberinfo);
            $this->display();
        }else if(IS_AJAX){

            $province = I('post.province');
            // echo $province; die;
            if(!empty($province)){

                $data['province'] = M('regions')->where(array('code' => $province))->getField('name');
            }

            $city = I('post.city');
            if(!empty($city)){

                $data['city']  = M('regions')->where(array('code' => $city))->getField('name');
                // $data['code'] = $city;
            }

            $address = I('post.address');
            if(!empty($address)){

                $data['address'] = $address;
            }

            // print_r($data); die;
            $map['id'] = $this->memberinfo['id'];

            $User = M('members');
            $result = $User->where($map)->data($data)->save();
            // var_dump($result); die;
            if(!empty($result)){

                echo json_encode(1);
            }else{

                echo json_encode(0);
            }
        }
    }



    //修改用户名
    public function modify_name(){

         if(IS_GET){
            $this->assign("memberinfo", $this->memberinfo);
            $this->display();
        }else if(IS_AJAX){

            $username = I('post.username');
            
            if(!empty($username)){

                $data['username'] = $username;
            }
            $map['id'] = $this->memberinfo['id'];

            $User = M('members');

            $chk_back = chk_bad_words($username,2);
            if($chk_back){

                echo json_encode(2);
            }else{

                $result = $User->where($map)->data($data)->save();
                if(!empty($result)){

                    echo json_encode(1);
                }else{

                    echo json_encode(0);
                }
            }
        }
    }



    /**
     * 用户参与项目
     */
    public function my_orders(){

        if(IS_GET){


            $mid = $this->memberinfo['id'];

            $list = $this->get_my_takepart($mid);

            // foreach ($list as $k => $v) {
            //     # code...
            //     $list[$k]['fouding'] = M('fundings')->where(array('id' => $v['for_id']))->find();
            //     $list[$k]['fouding']['packageid'] = explode(',',$list[$k]['fouding']['packageid']);
            //     foreach ($list[$k]['fouding']['packageid'] as $key => $value) {
            //         # code...
            //         $list[$k]['fouding']['packageid'][$key] = M('fundings_package')->where(array('id' => $value))->getField('name');
            //     }
            //     $list[$k]['fouding']['packagename'] = implode(',', $list[$k]['fouding']['packageid']);
            // }
            // print_r($list); die;
            $this->assign('list',$list);
            $this->assign("from_channel", 1);
            
            $this->display();
        }
    }


    /**
     * 用户健康豆明细
     */
    public function beans_detail(){

        if(IS_GET){
            $mid = $this->memberinfo['id'];

            $list = $this->_get_member_beans_log($mid);
            // print_r($list); die;
            $this->assign('list',$list);
            $this->display();
        }
    }



    /**
     * 众测攻略
     */
    public function guides(){

        if(IS_GET){

            // print_r($this->memberinfo); die;
            $this->display();
        }
    }
    
    /*
     * 我的红包
     * 罗列我获取到的所有红包
     * 1. 未用的在前面，时间顺序排序
     * 2. 已用和过期的排序在后面
     * 
     */
    /*
     * 我的红包
     */
    public function my_redpack() {
        //红包数量
        $my_redpack_count = I('get.my_redpack_count');

        // echo $my_redpack_count;die;
        $DB_redpack_receive_records =M("redpack_receive_records");
        $map['fd_redpack_receive_records.mid']=  $this->memberinfo['id'];
        $map['is_used'] = 0;
        $map['fd_redpack_receive_records.etime']=array('gt',I("server.REQUEST_TIME"));

        $res = $DB_redpack_receive_records->where($map)->join("LEFT JOIN fd_redpack_create_records ON fd_redpack_create_records.id = fd_redpack_receive_records.rp_id")->order('cash')->limit(10)->getField('fd_redpack_receive_records.id as id,fd_redpack_receive_records.mid as mid,fd_redpack_receive_records.openid as openid,fd_redpack_receive_records.rp_id as rp_id,fd_redpack_receive_records.is_used as is_used,fd_redpack_receive_records.ctime as ctime,fd_redpack_receive_records.etime as etime,fd_redpack_receive_records.fid as fid,fd_redpack_create_records.random_code as random_code,fd_redpack_create_records.redpack_code as redpack_code,fd_redpack_create_records.cash as cash,fd_redpack_create_records.isactived as isactived,fd_redpack_create_records.slogan as slogan');
        foreach ($res as $key => $value) {
            # code...
            $res[$key]['cash'] = ($value['cash'] * 100)/100;
        }
        // print_r($res); die;
        $this->assign('my_redpack_count',$my_redpack_count);
        $this->assign("result", $res);
        
        $this->display();
    }


    /*
     * 红包的领取
     * 0. 判断是否同一个人
     * 1. 接收rp_id
     * 2. 判断 红包是否被领取了
     * 3. 没有领取的红包去添加到记录
     * 
     */
    public function redpack_rank() {
        $DB_redpack_create_records = M("redpack_create_records");
        $DB = M("redpack_receive_records");
        $rp_id = I("get.rp_id");
        
        
        
        $res_redpack = $DB_redpack_create_records->find($rp_id);
        $openid = session("openid");
        $mid = session("mid");
        /*
         * 判断是否是同一个人
         * 
         */
//        if($res_redpack['openid']==$openid)
//        {
//            //跳转到首页
//            redirect(U('M/Index/index'));
//        }
        
        if($res_redpack['isactived']==1)
        {
            //说明是已用过的
//            redirect(U('M/Index/index'));
            
        }
        else
        {
//            $openid = session("openid");
            

            $data['mid']=$mid;
            $data['openid']=$openid;
            $data['rp_id']=$rp_id;
            $data['is_used']=0;
            $data['ctime']=I("server.REQUEST_TIME");
            $data['etime']=$res_redpack['etime'];
            $data['utime']=$data['ctime'];
            $data['fid']=$res_redpack['fid'];
            
            $id = $DB->add($data);
            
            if($id)
            {
                $DB_redpack_create_records->id = $rp_id;
                $DB_redpack_create_records->isactived = 1;
                $DB_redpack_create_records->save();
            }
        }
        
        $show_data['avatar']= $this->_get_one_avatar($mid);
        $show_data['redpack_cash'] = $res_redpack['cash'];
        $show_data['btime'] = date("Y.m.d",$res_redpack['ctime']);
        $show_data['etime'] = date("Y.m.d",$res_redpack['etime']);
        $show_data['fdid'] = $res_redpack['fid'];

        
        /*
         * 获取同一个 random_code 的所有红包的领取情况
         */
        $res_ranks = $DB_redpack_create_records->where(array('random_code'=>$res_redpack['random_code'],'isactived'=>1))->order('ctime DESC')->limit(10)->select();
        
        foreach ($res_ranks as $key => $value) {
            $tmp = $this->_get_redpack_member_info($value['id']);
            if($tmp)
            {
               $res_ranks[$key]['member']=  $tmp;
            }
            else
            {
                unset($res_ranks[$key]);
            }
            
            
        }
        
        $this->assign("show_data", $show_data);
        $this->assign('res_ranks', $res_ranks);
        
        $this->display();
        
    }
    
    
    /*
     * 获取指定红包 random_code 的领取信息
     */
    private function _get_redpack_member_info($rp_id){
        $DB = M("redpack_receive_records");
        $res = $DB->where(array('rp_id'=>$rp_id))->find();
        if(empty($res))
        {
            return FALSE;
        }
        else
        {
            $data['avatar']=  $this->_get_one_avatar($res['mid']);
            $data['username']=  $this->_get_member_nickname($res['mid']);

            return $data;
        }
        
        
        
    }

    




    /**
     * 获取健康豆记录
     */
    private function _get_member_beans_log($mid){

        $map['mid'] = $mid;
        $sys_beans_log = M('sys_beans_log');

        $list = $sys_beans_log->where($map)->order('ctime DESC')->select();

        return $list;
    }

    /**
     * 项目关注表
     */
    public function collections(){

        if(IS_GET){

            $mid = $this->memberinfo['id'];
            $ctype = 1;
            $return_type = 1;
            $list = $this->_get_member_collection($mid,$ctype,$return_type);

            /**
             * 循环获取关注项目的项目列表
             */
            $DB_f = M('fundings');
            foreach ($list as $key =>$value) {
                # code...
//                $list[$k]['fouding'] = M('fundings')->where(array('id' => $v['for_id']))->find();
//                $list[$k]['fouding']['packageid'] = explode(',',$list[$k]['fouding']['packageid']);
//                foreach ($list[$k]['fouding']['packageid'] as $key => $value) {
//                    # code...
//                    $list[$k]['fouding']['packageid'][$key] = M('fundings_package')->where(array('id' => $value))->getField('name');
//                }
//                $list[$k]['fouding']['packagename'] = implode(',', $list[$k]['fouding']['packageid']);
//                
//                $my_takepart2[$key]=$my_takepart[$key];
                
                $list[$key]['fd_info'] =  $DB_f->find($value['for_id']);
                
                $list[$key]['thumb']=  ($list[$key]['fd_info']['thumb']);
                $list[$key]['location']=  ($list[$key]['fd_info']['location']);
                $list[$key]['packagename']=  $this->get_name_by_packageid($list[$key]['fd_info']['packageid']);
                $list[$key]['pjname']=  ($list[$key]['fd_info']['pjname']);
                $list[$key]['state']=  ($list[$key]['fd_info']['state']);
                if(mb_strlen($list[$key]['packagename'],"utf-8")>10)
                {
                    $list[$key]['packagename'] = mb_substr($list[$key]['packagename'], 0,8,'utf-8')."...";

                }
                $list[$key]['show_mark_icon']=  $this->_get_fouding_list_mark(0,$list[$key]['fd_info']['result'],$list[$key]['fd_info']['state']);

                $list[$key]['rate'] = round($list[$key]['fd_info']['finish']*100/($list[$key]['fd_info']['emoney']+$list[$key]['fd_info']['smoney']*$list[$key]['fd_info']['samnum']),0);
                $list[$key]['testing_result']=$this->_get_testing_report_short_analyze($value['testreportid']);
                
                switch ($value['state']) {
                    case 0:
                        $list[$key]['isshow_batch']= 0;

                        break;
                    case 1:
                        $list[$key]['isshow_batch']= 0;

                        break;
                    case 2:
                        $list[$key]['isshow_batch']= 0;

                        break;
                    case 3:
                        $list[$key]['isshow_batch']= 1;

                        break;

                    default:
                        $list[$key]['isshow_batch']= 0;
                        break;
                }
                
                
            }
            
            
//                         print_r($list); die;
            $this->assign('list',$list);
            $this->display();
        }
    }
    
    
    /*
     * 用户进入我的模板，获取更多信息
     * 参与的项目
     * 关注的项目
     * 我的健康豆
     * 收藏的文章
     * 
     */
    public function _get_member_additional_info($mid) {
         //我参与的
        $my_takepart = $this->get_my_takepart($mid);

        $data['my_takepart_count'] = count($my_takepart);
        
        //关注的项目
        
        $data['my_follow_founding_count'] = $this->_get_member_collection($mid, 1, 0);
        
        //我的健康豆
        $data['my_beans_count'] = $this->memberinfo['beans'];
        
        //我收藏的文章
        
        //可用的红包数目
        $DB_redpack_receive_records =M("redpack_receive_records");
        $map['mid'] = $mid;
        $map['is_used']=0;
        $map['fd_redpack_receive_records.etime']=array('gt',I("server.REQUEST_TIME"));
        
        
        
        $data['my_redpack_count'] = $DB_redpack_receive_records->where($map)->count();
        
        return $data;
        
    }

    
    /*
     * 获取我参与的项目列表
     */
    
    private function get_my_takepart($mid){

        $DB_sponsor = M('fundings_sponsor');
        
        

        $my_takepart = $DB_sponsor->query("SELECT `fd_fundings_sponsor`.`id` as sponsorid,`fd_fundings_sponsor`.`fid` as id, `fd_fundings`.`ctime` as ctime,`fd_fundings`.`batch` as batch, `fd_fundings`.`packageid` as packageid,`fd_fundings`.`pjname` as pjname,`fd_fundings`.`state` as state,`fd_fundings`.`location` as location,`fd_fundings`.`result` as result,`fd_fundings`.`thumb` as thumb,`fd_fundings`.`finish` as finish,(`fd_fundings`.`emoney`+`fd_fundings`.`smoney`*`fd_fundings`.`samnum`) as emoney FROM `fd_fundings_sponsor`  LEFT JOIN `fd_fundings` ON `fd_fundings_sponsor`.fid = `fd_fundings`.id WHERE `fd_fundings_sponsor`.`mid`=".$mid." and `fd_fundings_sponsor`.`status`=1  GROUP BY fid ORDER BY state,ctime");
//        print_r($DB_sponsor->getLastSql());
//        print_r($my_takepart);
        
        if(!empty($my_takepart)){
            $DB_f = M('fundings');
            foreach ($my_takepart as $key => $value) {
                
                $res_tmp =  $DB_f->find($value['id']);
                
                if(!empty($res_tmp))
                {
                    $my_takepart2[$key]=$my_takepart[$key];
                    $my_takepart2[$key]['packagename']=  $this->get_name_by_packageid($value['packageid']);
                    if(mb_strlen($my_takepart2[$key]['packagename'],"utf-8")>10)
                    {
                        $my_takepart2[$key]['packagename'] = mb_substr($my_takepart2[$key]['packagename'], 0,8,'utf-8')."...";

                    }
                    $my_takepart2[$key]['show_mark_icon']=  $this->_get_fouding_list_mark(0,$value['result'],$value['state']);
                    
                    $my_takepart2[$key]['rate'] = round($value['finish']*100/($value['emoney']+$value['smoney']*$value['samnum']),0);
                    
                    if(strlen($my_takepart2[$key]['batch'])>12)
                    {
                        $my_takepart2[$key]['batch']= substr($my_takepart2[$key]['batch'], 0,12)."...";
                    }
                    
                     $my_takepart2[$key]['testing_result']=$this->_get_testing_report_short_analyze($value['testreportid']);
                     
                     switch ($value['state']) {
                    case 0:
                        $my_takepart2[$key]['isshow_batch']= 0;

                        break;
                    case 1:
                        $my_takepart2[$key]['isshow_batch']= 0;

                        break;
                    case 2:
                        $my_takepart2[$key]['isshow_batch']= 0;

                        break;
                    case 3:
                        $my_takepart2[$key]['isshow_batch']= 1;

                        break;

                    default:
                        $my_takepart2[$key]['isshow_batch']= 0;
                        break;
                }
                    
                }
                
            }
            $my_takepart3 = (array_values($my_takepart2));
            
            
//            print_r($my_takepart2);
            return $my_takepart3;
            
        }
        
        
    }
    
    
    /*
     * 获取报告的列表显示的不合格分析
     */
    public function _get_testing_report_short_analyze($id) {
        if(empty($id))
        {
            return "";
        }
        else
        {
            $DB = M("testreport");
            $res = $DB->find($id);
            if(empty($res))
            {
                return "";
            }
            else
            {
                return $res['content'];
            }
            
        }
        
    }
    
    /*
     * 获取收藏资料
     * $return_type , 0 代表 是返回数字， 1代表返回数据
     */
    private function _get_member_collection($mid,$ctype,$return_type) {
        if($ctype == 2){
            $map['ctype'] = array('in','2,6');
        }else{

            $map['ctype'] = $ctype;
        }
        
        // $map['mid']=$mid;
        $res = M("collections")->where($map)->select();
        // print_r($res); die;
        if($return_type==0)
        {
            return count($res);
        }
        else
        {
            if(!empty($res))
            {
                return $res;
            }
            else
            {
                return "";
            }
        } 
    }


    /**
     * 收藏文章获取
     */
    public function news(){

        if(IS_GET){

            $mid = $this->memberinfo['id'];
            $ctype = 2;
            $return_type = 1;
            $list = $this->_get_member_collection($mid,$ctype,$return_type);

            foreach ($list as $k => $v) {
                # code...
                $list[$k]['new'] = M('news')->where(array('id' => $v['for_id']))->find();
            }

//             print_r($list); die;
            $this->assign('list',$list);
            $this->display();
        }
    }
    
    /*
     * 健康豆规则
     */
    public function bean_rule() {
        $this->display();
    }
    
    
    
    /*
     * 我的红包分页功能
     */
    
    public function get_my_redpack_by_page() {
//       获取需要的类型
        $type = I("get.type");
        $mid = session("mid");
        $pagecount = I("get.pagecount");
        
        if(empty($pagecount))
        {
            $pagecount=0;
        }
        
        if($type==1)
        {
            $DB_redpack_receive_records =M("redpack_receive_records");
            $map['fd_redpack_receive_records.mid']=$mid;

            $where['is_used']  = 1;
            $where['fd_redpack_receive_records.etime']  = array('lt',I("server.REQUEST_TIME"));
            $where['_logic'] = 'or';

            $map['_complex'] = $where;

            $res = $DB_redpack_receive_records->where($map)->join("LEFT JOIN fd_redpack_create_records ON fd_redpack_create_records.id = fd_redpack_receive_records.rp_id")->order('cash')->limit($pagecount*10,10)->getField('fd_redpack_receive_records.id as id,fd_redpack_receive_records.mid as mid,fd_redpack_receive_records.openid as openid,fd_redpack_receive_records.rp_id as rp_id,fd_redpack_receive_records.is_used as is_used,fd_redpack_receive_records.ctime as ctime,fd_redpack_receive_records.etime as etime,fd_redpack_receive_records.fid as fid,fd_redpack_create_records.random_code as random_code,fd_redpack_create_records.redpack_code as redpack_code,fd_redpack_create_records.cash as cash,fd_redpack_create_records.isactived as isactived,fd_redpack_create_records.slogan as slogan');
        }
        else
        {
            //默认未用的
            $DB_redpack_receive_records =M("redpack_receive_records");
            $map['fd_redpack_receive_records.mid']=$mid;
            $map['is_used']=0;
            $map['fd_redpack_receive_records.etime']=array('gt',I("server.REQUEST_TIME"));

            $res = $DB_redpack_receive_records->where($map)->join("LEFT JOIN fd_redpack_create_records ON fd_redpack_create_records.id = fd_redpack_receive_records.rp_id")->order('cash')->limit($pagecount*10,10)->getField('fd_redpack_receive_records.id as id,fd_redpack_receive_records.mid as mid,fd_redpack_receive_records.openid as openid,fd_redpack_receive_records.rp_id as rp_id,fd_redpack_receive_records.is_used as is_used,fd_redpack_receive_records.ctime as ctime,fd_redpack_receive_records.etime as etime,fd_redpack_receive_records.fid as fid,fd_redpack_create_records.random_code as random_code,fd_redpack_create_records.redpack_code as redpack_code,fd_redpack_create_records.cash as cash,fd_redpack_create_records.isactived as isactived,fd_redpack_create_records.slogan as slogan');

        }
            
            
    }
    
    /*
     * 我的历史红包
     */
    public function my_redpack_history() {
        $DB_redpack_receive_records =M("redpack_receive_records");
        // $map['mid']= 1;
        $mid = 1;

        $where['is_used']  = 1;
        $where['fd_redpack_receive_records.etime']  = array('lt',I("server.REQUEST_TIME"));
        $where['_logic'] = 'or';

        $map['_complex'] = $where;
        $map['fd_redpack_receive_records.mid']=$mid;

        $res = $DB_redpack_receive_records->where($map)->join("LEFT JOIN fd_redpack_create_records ON fd_redpack_create_records.id = fd_redpack_receive_records.rp_id")->order('cash')->limit(10)->getField('fd_redpack_receive_records.id as id,fd_redpack_receive_records.mid as mid,fd_redpack_receive_records.openid as openid,fd_redpack_receive_records.rp_id as rp_id,fd_redpack_receive_records.is_used as is_used,fd_redpack_receive_records.ctime as ctime,fd_redpack_receive_records.etime as etime,fd_redpack_receive_records.fid as fid,fd_redpack_create_records.random_code as random_code,fd_redpack_create_records.redpack_code as redpack_code,fd_redpack_create_records.cash as cash,fd_redpack_create_records.isactived as isactived,fd_redpack_create_records.slogan as slogan');
        // print_r($DB_redpack_receive_records->getLastSql());
        // exit();
        foreach ($res as $key => $value) {
            # code...
            $res[$key]['cash'] = ($value['cash'] * 100)/100;

        }
        // print_r($res); die;
        $this->assign("result", $res);
        $this->display();
    }



    /**
     * 红包说明
     */
    public function redpack_introductions(){

        if(IS_GET){

            $this->display();
        }
    }
    
    
    /*
     * 个人中心的分享页面
     */
    public function share_from_app() {
        $this->display();
    }

}